package vip.meeet.jdk.thread;

import java.util.Map;
import java.util.Set;

public class PrintStack {

    public static void main(String[] args) {
        while (true){
            printStack();
        }
    }

    private static void printStack(){
        Map<Thread, StackTraceElement[]> allStackTraces = Thread.getAllStackTraces();
        Set<Map.Entry<Thread, StackTraceElement[]>> entries = allStackTraces.entrySet();
        entries.forEach(threadEntry -> {
            System.out.println(threadEntry.getKey());
            StackTraceElement[] value = threadEntry.getValue();
            for(StackTraceElement ste : value){
                System.out.println(ste);
            }
        });
    }
}
